package lapsnake.model.stmt;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.model.misc.LapExcepthandler;
import lapsnake.py.ast.ASTHelperFactory; import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for TryExcept nodes*/
public class LapTryExcept extends LapStatement {
	public final ChildList<LapStatement> body = new ChildList<>(this, LapStatement.class, false);
	@NewRow public final ChildList<LapExcepthandler> handlers = new ChildList<>(this, LapExcepthandler.class, false);
	@NewRow public final ChildList<LapStatement> orelse = new ChildList<>(this, LapStatement.class, false);
	
	public LapTryExcept(PyAST pyAST, ChildField<? super LapTryExcept> parent, TryExcept node) throws PropertyVetoException {
		super(pyAST, parent, node);
	
		ASTHelperFactory.makeHelpers(pyAST, body, node.getInternalBody());
		ASTHelperFactory.makeHelpers(pyAST, handlers, node.getInternalHandlers());
		ASTHelperFactory.makeHelpers(pyAST, orelse, node.getInternalOrelse());
		
		buildTextNodes(node);
	}

	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == body)
			return new JTreeLabel("Try:", true);
		else if(childField == handlers)
			return new JTreeLabel("Except:", true);
		else
			return new JTreeLabel("Else:", true);
	}
}
